﻿using GalaSoft.MvvmLight;
using System.Windows.Media.Media3D;
using WorldSimulator;
using WorldSimulator.PhysicsEngine;

namespace WorldSimulatorWPF.ViewModel
{
	/// <summary>
	/// ViewModel for a 3D Sphere
	/// </summary>
	public class SphereViewModel : ViewModelBase
	{
		//// PRIVATE FIELDS

		/// <summary>
		/// PhysicalObject the sphere gets its location / rotation / size from
		/// </summary>
		private IPhysicalObject _obj;

		//// CONSTRUCTION

		/// <summary>
		/// New sphere from IPhysicalObject
		/// </summary>
		/// <param name="obj"></param>
		public SphereViewModel(IPhysicalObject obj)
		{
			this._obj = obj;
		}

		//// PUBLIC FIELDS

		/// <summary>
		/// Gets or sets the X-value
		/// </summary>
		public double X
		{
			get
			{
				return this._obj.Location.X;
			}

			set
			{
				this._obj.Location = new MyVector3D(value, this.Y, this.Z);
			}
		}

		/// <summary>
		/// Gets or sets the Y-value
		/// </summary>
		public double Y
		{
			get
			{
				return this._obj.Location.Y;
			}

			set
			{
				this._obj.Location = new MyVector3D(this.X, value, this.Z);
			}
		}

		/// <summary>
		/// Gets or sets the Z-value
		/// </summary>
		public double Z
		{
			get
			{
				return this._obj.Location.Z;
			}

			set
			{
				this._obj.Location = new MyVector3D(this.X, this.Y, value);
			}
		}

		/// <summary>
		/// The sphere's half radius
		/// </summary>
		public double HalfRadius
		{
			get
			{
				return this._obj.Radius / 2;
			}
		}

		/// <summary>
		/// The sphere's radius
		/// </summary>
		public double Radius
		{
			get
			{
				return this._obj.Radius;
			}
		}
		//// PUBLIC METHODS

		/// <summary>
		/// Raises the PropertyChanged-Events of X,Y and Z
		/// </summary>
		public void RaisePropertyChanged()
		{
			this.RaisePropertyChanged("X");
			this.RaisePropertyChanged("Y");
			this.RaisePropertyChanged("Z");
		}
	}
}